
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>添加角色-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <link rel="stylesheet" href="../../static/css/font.css" />
    <link rel="stylesheet" href="../../static/css/weadmin.css" />
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="weadmin-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required|maxLength" placeholder="请输入名称" autocomplete="off" class="layui-input" maxlength="255" onpropertychange="if(value.length>255) value=value.substr(0,255)">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图标</label>
            <div class="layui-input-block">
                <input type="text" name="icon" lay-verify="maxLength" placeholder="请输入图标" autocomplete="off" class="layui-input" maxlength="255" onpropertychange="if(value.length>255) value=value.substr(0,255)">
                https://www.layui.com/doc/element/icon.html
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">链接</label>
            <div class="layui-input-block">
                <input type="text" name="url" lay-verify="required|maxLength" placeholder="请输入链接" autocomplete="off" class="layui-input" maxlength="255" onpropertychange="if(value.length>255) value=value.substr(0,255)">

            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">页面标识</label>
            <div class="layui-input-block">
                <input type="checkbox" name="isView" lay-skin="switch">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">输入排序权重</label>
            <div class="layui-input-block">
                <input type="text" name="sortRank"   lay-verify="number" placeholder="请输入排序权重越小越前默认0" autocomplete="off" class="layui-input">
            </div>
        </div>
        <input type="hidden" name="parentId"  value="0" />
        <input type="hidden" name="parentIds"  value="0" />
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="../../static/layui/layui.js" charset="utf-8"></script>
<script>
    layui.extend({
        admin: '{/}../../static/js/admin'
    });
    layui.use('form', function(){
        var form = layui.form;
        form.verify({
           maxLength:function (value, item) {
               if(value.length>255){
                   return '长度不能超多255个';
               }
           }
        });
        //监听提交
        form.on('submit(add)', function(data){
            var $ = layui.jquery ;
            if (data.field.isView == "on") {
                data.field.isView = true;
            }else{
                data.field.isView = false;
            }
            $.ajax({
                type: "post",
                dataType: "json",
                url: "/permission/savePermission",
                contentType: "application/json;charset=UTF-8",//指定消息请求类型
                data: JSON.stringify(data.field),
                success: function (data) {
                    if(data.code == null || data.code != 200){
                        layer.msg(data.msg);
                    }else{
                        layer.alert("增加成功", {
                            icon: 6
                        },function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //关闭父级页面的表格
                            parent.layui.table.reload('list');
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>